<!DOCTYPE html>
<html lang="zh-CN,en,zh-HK,zh-TW,default">
<head hexo-theme='https://github.com/volantis-x/hexo-theme-volantis/tree/4.0.0'>
  <meta charset="utf-8">
  <!-- SEO相关 -->
  
    
  
  <!-- 渲染优化 -->
  <meta name="renderer" content="webkit">
  <meta name="force-rendering" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="HandheldFriendly" content="True" >
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta http-equiv='x-dns-prefetch-control' content='on' />

  <!-- 页面元数据 -->
  
  <title>第三章 数据和C - HardyDragon Index</title>
  
    <meta name="keywords" content="C Notes">
  

  

  <!-- feed -->
  

  <!-- import meta -->
  
    
      <meta name="msapplication-TileColor" content="#ffffff">
    
      <meta name="msapplication-config" content="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/blog/favicon/browserconfig.xml">
    
      <meta name="theme-color" content="#ffffff">
    
  

  <!-- link -->
  <link rel='dns-prefetch' href='https://cdn.jsdelivr.net'>
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.14/css/all.min.css">

  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css">

  

  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-waves@0.7.6/dist/waves.min.css">

  

  

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10/dist/APlayer.min.css">
  

  

  <!-- import link -->
  
  
  <link rel="apple-touch-icon" sizes="180x180" href="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/blog/favicon/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="https://s1.ax1x.com/2020/10/02/0l3pPe.png">
  <link rel="icon" type="image/png" sizes="16x16" href="https://s1.ax1x.com/2020/10/02/0l3pPe.png">
  <link rel="manifest" href="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/blog/favicon/site.webmanifest">
  <link rel="mask-icon" href="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/blog/favicon/safari-pinned-tab.svg" color="#5bbad5">
  <link rel="shortcut icon" href="https://s1.ax1x.com/2020/10/02/0l3pPe.png">
  

  
    
      
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.18.1/styles/solarized-light.css">

    
  
  
    
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  <!-- 脚本懒加载函数 -->
  <script>
  function loadScript(src, cb) {
    var HEAD = document.getElementsByTagName('head')[0] || document.documentElement;
    var script = document.createElement('script');
    script.setAttribute('type','text/javascript');
    if (cb) script.onload = cb;
    script.setAttribute('src', src);
    HEAD.appendChild(script);
  }
  //https://github.com/filamentgroup/loadCSS
  !function(c){"use strict";var e=function(e,t,n,r){var o,i=c.document,a=i.createElement("link");if(t)o=t;else{var d=(i.body||i.getElementsByTagName("head")[0]).childNodes;o=d[d.length-1]}var f=i.styleSheets;if(r)for(var l in r)r.hasOwnProperty(l)&&a.setAttribute(l,r[l]);a.rel="stylesheet",a.href=e,a.media="only x",function e(t){if(i.body)return t();setTimeout(function(){e(t)})}(function(){o.parentNode.insertBefore(a,t?o:o.nextSibling)});var s=function(e){for(var t=a.href,n=f.length;n--;)if(f[n].href===t)return e();setTimeout(function(){s(e)})};function u(){a.addEventListener&&a.removeEventListener("load",u),a.media=n||"all"}return a.addEventListener&&a.addEventListener("load",u),(a.onloadcssdefined=s)(u),a};"undefined"!=typeof exports?exports.loadCSS=e:c.loadCSS=e}("undefined"!=typeof global?global:this);
  </script>
  <script id="loadcss"></script>
</head>

<body>
  <header class="l_header always shadow blur "  >
  <div class='container'>
  <div class='wrapper'>
    <div class='nav-sub'>
      <p class="title"></p>
      <ul class='switcher nav-list-h m-phone' id="pjax-header-nav-list">
        <li><a class="s-comment fas fa-comments fa-fw" target="_self" href='javascript:void(0)'></a></li>
        
          <li><a class="s-toc fas fa-list fa-fw" target="_self" href='javascript:void(0)'></a></li>
        
      </ul>
    </div>
		<div class="nav-main">
      
        
        <a class="title flat-box" target="_self" href='/blog/'>
          
          
            <i class='https://s1.ax1x.com/2020/10/02/0l3pPe.png'></i>
          
          
            HardyDragon
          
        </a>
      

			<div class='menu navigation'>
				<ul class='nav-list-h m-pc'>
          
          
          
            
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/
                  
                  
                  
                    id="blog"
                  >
                  <i class='fas fa-rss fa-fw'></i>博客
                </a>
                
              </li>
            
          
          
            
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/categories/
                  
                  
                  
                    id="blogcategories"
                  >
                  <i class='fas fa-folder-open fa-fw'></i>分类
                </a>
                
              </li>
            
          
          
            
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/tags/
                  
                  
                  
                    id="blogtags"
                  >
                  <i class='fas fa-tags fa-fw'></i>标签
                </a>
                
              </li>
            
          
          
            
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/archives/
                  
                  
                  
                    id="blogarchives"
                  >
                  <i class='fas fa-archive fa-fw'></i>归档
                </a>
                
              </li>
            
          
          
            
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/friends/
                  
                  
                  
                    id="blogfriends"
                  >
                  <i class='fas fa-link fa-fw'></i>友链
                </a>
                
              </li>
            
          
          
            
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/about/
                  
                  
                  
                    id="blogabout"
                  >
                  <i class='fas fa-info-circle fa-fw'></i>关于
                </a>
                
                  <ul class="list-v">
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://blog.csdn.net/qq_44880154
                  
                  
                  
                    id="https:blogcsdnnetqq_44880154"
                  >
                  <i class='fas fa-fire fa-fw'></i>CSDN
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://gitee.com/hardychenlong
                  
                  
                  
                    id="https:giteecomhardychenlong"
                  >
                  <i class='fas fa-clock fa-fw'></i>gitee
                </a>
                
              </li>
            
          
                    
                  </ul>
                
              </li>
            
          
          
            
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" 
                  
                  
                  >
                  <i class='fas fa-ellipsis-v fa-fw'></i>更多
                </a>
                
                  <ul class="list-v">
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://github.com/volantis-x/hexo-theme-volantis/
                  
                  
                  
                    id="https:githubcomvolantis-xhexo-theme-volantis"
                  >
                  主题源码
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://github.com/volantis-x/hexo-theme-volantis/releases/
                  
                  
                  
                    id="https:githubcomvolantis-xhexo-theme-volantisreleases"
                  >
                  更新日志
                </a>
                
              </li>
            
          
                    
                      
            
              <hr>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" 
                  
                  
                  >
                  有疑问？
                </a>
                
                  <ul class="list-v">
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/faqs/
                  
                  
                  
                    id="blogfaqs"
                  >
                  看 FAQ
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://github.com/volantis-x/volantis-docs/
                  
                  
                  
                    id="https:githubcomvolantis-xvolantis-docs"
                  >
                  看 本站源码
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://github.com/volantis-x/hexo-theme-volantis/issues/
                  
                  
                  
                    id="https:githubcomvolantis-xhexo-theme-volantisissues"
                  >
                  提 Issue
                </a>
                
              </li>
            
          
                    
                  </ul>
                
              </li>
            
          
                    
                      
            
              <hr>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/archives/
                  
                  
                  
                    id="blogarchives"
                  >
                  公告和测试博文
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/examples/
                  
                  
                  
                    id="blogexamples"
                  >
                  示例博客
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/contributors/
                  
                  
                  
                    id="blogcontributors"
                  >
                  特别感谢
                </a>
                
              </li>
            
          
                    
                  </ul>
                
              </li>
            
          
          
				</ul>
			</div>

      <div class="m_search">
        <form name="searchform" class="form u-search-form">
          <i class="icon fas fa-search fa-fw"></i>
          <input type="text" class="input u-search-input" placeholder="搜索" />
        </form>
      </div>

			<ul class='switcher nav-list-h m-phone'>
				
					<li><a class="s-search fas fa-search fa-fw" target="_self" href='javascript:void(0)'></a></li>
				
				<li>
          <a class="s-menu fas fa-bars fa-fw" target="_self" href='javascript:void(0)'></a>
          <ul class="menu-phone list-v navigation white-box">
            
              
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/
                  
                  
                  
                    id="blog"
                  >
                  <i class='fas fa-rss fa-fw'></i>博客
                </a>
                
              </li>
            
          
            
              
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/categories/
                  
                  
                  
                    id="blogcategories"
                  >
                  <i class='fas fa-folder-open fa-fw'></i>分类
                </a>
                
              </li>
            
          
            
              
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/tags/
                  
                  
                  
                    id="blogtags"
                  >
                  <i class='fas fa-tags fa-fw'></i>标签
                </a>
                
              </li>
            
          
            
              
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/archives/
                  
                  
                  
                    id="blogarchives"
                  >
                  <i class='fas fa-archive fa-fw'></i>归档
                </a>
                
              </li>
            
          
            
              
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/friends/
                  
                  
                  
                    id="blogfriends"
                  >
                  <i class='fas fa-link fa-fw'></i>友链
                </a>
                
              </li>
            
          
            
              
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/about/
                  
                  
                  
                    id="blogabout"
                  >
                  <i class='fas fa-info-circle fa-fw'></i>关于
                </a>
                
                  <ul class="list-v">
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://blog.csdn.net/qq_44880154
                  
                  
                  
                    id="https:blogcsdnnetqq_44880154"
                  >
                  <i class='fas fa-fire fa-fw'></i>CSDN
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://gitee.com/hardychenlong
                  
                  
                  
                    id="https:giteecomhardychenlong"
                  >
                  <i class='fas fa-clock fa-fw'></i>gitee
                </a>
                
              </li>
            
          
                    
                  </ul>
                
              </li>
            
          
            
              
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" 
                  
                  
                  >
                  <i class='fas fa-ellipsis-v fa-fw'></i>更多
                </a>
                
                  <ul class="list-v">
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://github.com/volantis-x/hexo-theme-volantis/
                  
                  
                  
                    id="https:githubcomvolantis-xhexo-theme-volantis"
                  >
                  主题源码
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://github.com/volantis-x/hexo-theme-volantis/releases/
                  
                  
                  
                    id="https:githubcomvolantis-xhexo-theme-volantisreleases"
                  >
                  更新日志
                </a>
                
              </li>
            
          
                    
                      
            
              <hr>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" 
                  
                  
                  >
                  有疑问？
                </a>
                
                  <ul class="list-v">
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/faqs/
                  
                  
                  
                    id="blogfaqs"
                  >
                  看 FAQ
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://github.com/volantis-x/volantis-docs/
                  
                  
                  
                    id="https:githubcomvolantis-xvolantis-docs"
                  >
                  看 本站源码
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=https://github.com/volantis-x/hexo-theme-volantis/issues/
                  
                  
                  
                    id="https:githubcomvolantis-xhexo-theme-volantisissues"
                  >
                  提 Issue
                </a>
                
              </li>
            
          
                    
                  </ul>
                
              </li>
            
          
                    
                      
            
              <hr>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/archives/
                  
                  
                  
                    id="blogarchives"
                  >
                  公告和测试博文
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/examples/
                  
                  
                  
                    id="blogexamples"
                  >
                  示例博客
                </a>
                
              </li>
            
          
                    
                      
            
              <li>
                <a class="menuitem flat-box faa-parent animated-hover" href=/blog/contributors/
                  
                  
                  
                    id="blogcontributors"
                  >
                  特别感谢
                </a>
                
              </li>
            
          
                    
                  </ul>
                
              </li>
            
          
            
          </ul>
        </li>
			</ul>
		</div>
	</div>
  </div>
</header>

  <div class="l_body">
    <div class="l_cover">
  
    
    
        <div class='cover-wrapper post dock' style="display: none;">
          
            <div class='cover-backstretch'></div>
          
          <div class='cover-body'>
  <div class='top'>
    
    
      <p class="title">HardyDragon</p>
    
    
  </div>
  <div class='bottom'>
    <div class='menu navigation'>
      <div class='list-h'>
        
          
            <a target="_blank" rel="noopener" href="https://gitee.com/hardychenlong"
              
              
              id="https:giteecomhardychenlong">
              <img src='https://cdn.jsdelivr.net/gh/twitter/twemoji@13.0/assets/svg/1f5c3.svg'><p>Gitee</p>
            </a>
          
            <a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_44880154"
              
              
              id="https:blogcsdnnetqq_44880154">
              <img src='https://cdn.jsdelivr.net/gh/twitter/twemoji@13.0/assets/svg/1f516.svg'><p>CSDN</p>
            </a>
          
            <a target="_blank" rel="noopener" href="https://volantis.js.org/examples/"
              
              
              id="https:volantisjsorgexamples">
              <img src='https://cdn.jsdelivr.net/gh/twitter/twemoji@13.0/assets/svg/1f396.svg'><p>示例</p>
            </a>
          
            <a target="_blank" rel="noopener" href="https://volantis.js.org/examples/"
              
              
              id="https:volantisjsorgexamples">
              <img src='https://cdn.jsdelivr.net/gh/twitter/twemoji@13.0/assets/svg/1f389.svg'><p>社区</p>
            </a>
          
            <a href="/blog/archives/"
              
              
              id="blogarchives">
              <img src='https://cdn.jsdelivr.net/gh/twitter/twemoji@13.0/assets/svg/1f4f0.svg'><p>博客</p>
            </a>
          
            <a target="_blank" rel="noopener" href="https://github.com/volantis-x/hexo-theme-volantis/"
              
              
              id="https:githubcomvolantis-xhexo-theme-volantis">
              <img src='https://cdn.jsdelivr.net/gh/twitter/twemoji@13.0/assets/svg/1f9ec.svg'><p>源码</p>
            </a>
          
        
      </div>
    </div>
  </div>
</div>

          <div class="scroll-down" style="display: none;"><i class="fa fa-chevron-down scroll-down-effects"></i></div>
        </div>
    
  
  </div>
  
    <div class='safearea'>
      <div class='body-wrapper' id="pjax-container">
        
          <!--此文件用来存放一些不方便取值的变量--> 
<!--思路大概是将值藏到重加载的区域内--> 
 
 
 
<div id="pjax-data" style="display: none"> 
  <div id="pjax-ispage">true</div> 
  <div id="pjax-pageTitle">第三章 数据和C</div> 
  <div id="pjax-enable-cover">true</div> 
  <div id="pjax-comment-path"></div> 
  <div id="pjax-comment-placeholder"></div> 
</div> 
 
 
<script> 
  // 处理封面 此时 jquery 还没加载 
  if ("none" == "none") { // 移除封面 
    document.getElementsByClassName('cover-wrapper')[0].style.display = "none"; 
    document.getElementsByClassName('l_header', 'cover-wrapper')[0].classList.add("show"); 
  } else { 
    if ("none" == "half") { // 半屏 
      document.getElementsByClassName('cover-wrapper')[0].setAttribute('id', 'half'); 
      document.getElementsByClassName('scroll-down')[0].style.display = "none"; 
    } else if ("none" == "full") { // 全屏 
      document.getElementsByClassName('cover-wrapper')[0].setAttribute('id', 'full'); 
      document.getElementsByClassName('scroll-down')[0].style.display = ""; 
    } 
    document.getElementsByClassName('cover-wrapper')[0].style.display = ""; 
    document.getElementsByClassName('l_header', 'cover-wrapper')[0].classList.remove("show"); 
  } 
</script> 
 

        
        

<div class='l_main'>
  <article class="article post white-box reveal md shadow article-type-post" id="post" itemscope itemprop="blogPost">
  


  
  <div class="article-meta" id="top">
    
    
    
      <h1 class="title">
        第三章 数据和C
      </h1>
      <div class='new-meta-box'>
        
          
            
<div class='new-meta-item author'>
  <a class='author' href="/" rel="nofollow">
    <img no-lazy src="">
    <p>请设置文章作者</p>
  </a>
</div>

          
        
          
            

          
        
          
            <div class="new-meta-item date">
  <a class='notlink'>
    <i class="fas fa-calendar-alt fa-fw" aria-hidden="true"></i>
    <p>发布于：2021年3月22日</p>
  </a>
</div>

          
        
          
            
  <div class="new-meta-item browse leancloud">
    <a class='notlink'>
      
      <div id="lc-pv" data-title="第三章 数据和C" data-path="/blog/2021/03/22/%E7%AC%AC%E4%B8%89%E7%AB%A0%E6%95%B0%E6%8D%AE%E5%92%8CC/">
        <i class="fas fa-eye fa-fw" aria-hidden="true"></i>
        <span id='number'><i class="fas fa-circle-notch fa-spin fa-fw" aria-hidden="true"></i></span>
        次浏览
      </div>
    </a>
  </div>


          
        
      </div>
    
  </div>


  
  <h1 id="第三章-数据和C"><a href="#第三章-数据和C" class="headerlink" title="第三章 数据和C"></a>第三章 数据和C</h1><h2 id="3-1-示例程序"><a href="#3-1-示例程序" class="headerlink" title="3.1 示例程序"></a><a href="#3.1">3.1 示例程序</a></h2><h2 id="3-2-变量和常量数据"><a href="#3-2-变量和常量数据" class="headerlink" title="3.2 变量和常量数据"></a><a href="#3.2">3.2 变量和常量数据</a></h2><h2 id="3-3-数据：数据类型关键字"><a href="#3-3-数据：数据类型关键字" class="headerlink" title="3.3 数据：数据类型关键字"></a><a href="#3.3">3.3 数据：数据类型关键字</a></h2><h3 id="3-3-1-整数和浮点数"><a href="#3-3-1-整数和浮点数" class="headerlink" title="3.3.1 整数和浮点数"></a>3.3.1 整数和浮点数</h3><h3 id="3-3-2-整数"><a href="#3-3-2-整数" class="headerlink" title="3.3.2 整数"></a>3.3.2 整数</h3><h3 id="3-3-3-浮点数"><a href="#3-3-3-浮点数" class="headerlink" title="3.3.3 浮点数"></a>3.3.3 浮点数</h3><h2 id="3-4-C语言基本数据类型"><a href="#3-4-C语言基本数据类型" class="headerlink" title="3.4 C语言基本数据类型"></a><a href="#3.4">3.4 C语言基本数据类型</a></h2><h3 id="int类型"><a href="#int类型" class="headerlink" title="int类型"></a>int类型</h3><h3 id="其他数据类型"><a href="#其他数据类型" class="headerlink" title="其他数据类型"></a>其他数据类型</h3><h3 id="使用其他字符：char类型"><a href="#使用其他字符：char类型" class="headerlink" title="使用其他字符：char类型"></a>使用其他字符：char类型</h3><h3 id="Bool类型"><a href="#Bool类型" class="headerlink" title="_Bool类型"></a>_Bool类型</h3><h3 id="可移植类型：stdint-h和inttypes-h"><a href="#可移植类型：stdint-h和inttypes-h" class="headerlink" title="可移植类型：stdint.h和inttypes.h"></a>可移植类型：stdint.h和inttypes.h</h3><h3 id="float、double、和long、double"><a href="#float、double、和long、double" class="headerlink" title="float、double、和long、double"></a>float、double、和long、double</h3><h3 id="复数和虚数类型"><a href="#复数和虚数类型" class="headerlink" title="复数和虚数类型"></a>复数和虚数类型</h3><h3 id="其他类型"><a href="#其他类型" class="headerlink" title="其他类型"></a>其他类型</h3><h3 id="类型大小"><a href="#类型大小" class="headerlink" title="类型大小"></a>类型大小</h3><h2 id="3-5-使用数据类型"><a href="#3-5-使用数据类型" class="headerlink" title="3.5 使用数据类型"></a><a href="#3.5">3.5 使用数据类型</a></h2><h2 id="3-6-参数和陷阱"><a href="#3-6-参数和陷阱" class="headerlink" title="3.6 参数和陷阱"></a><a href="#3.6">3.6 参数和陷阱</a></h2><h2 id="3-7-转义序列示例"><a href="#3-7-转义序列示例" class="headerlink" title="3.7 转义序列示例"></a><a href="#3.7">3.7 转义序列示例</a></h2><h3 id="3-7-1-程序运行情况"><a href="#3-7-1-程序运行情况" class="headerlink" title="3.7.1 程序运行情况"></a>3.7.1 程序运行情况</h3><h3 id="3-7-2-刷新输出"><a href="#3-7-2-刷新输出" class="headerlink" title="3.7.2 刷新输出"></a>3.7.2 刷新输出</h3><h2 id="3-8-关键概念"><a href="#3-8-关键概念" class="headerlink" title="3.8 关键概念"></a><a href="#3.8">3.8 关键概念</a></h2><h2 id="3-9-本章小结"><a href="#3-9-本章小结" class="headerlink" title="3.9 本章小结"></a><a href="#3.9">3.9 本章小结</a></h2><h2 id="3-10-复习题"><a href="#3-10-复习题" class="headerlink" title="3.10 复习题"></a><a href="#3.10">3.10 复习题</a></h2><h2 id="3-11-编程练习"><a href="#3-11-编程练习" class="headerlink" title="3.11 编程练习"></a><a href="#3.11">3.11 编程练习</a></h2><hr>
<p><strong><a name="3.1">3.1 示例程序</a></strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* platinum.c -- your weight in platinum*/</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* code */</span></span><br><span class="line">    <span class="keyword">float</span> weight;</span><br><span class="line">    <span class="keyword">float</span> value;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Are you worth your weight in platinum?\n&quot;</span>);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Let&#x27;s check it out.\n&quot;</span>);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Please enter your weight in pounds:&quot;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* 获取用户输入*/</span></span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%f&quot;</span>, &amp;weight);</span><br><span class="line">    <span class="comment">/* 假设白金的的价格是每司￥1700*/</span></span><br><span class="line">    <span class="comment">/* 14.5833 用于换算 */</span></span><br><span class="line">    value = <span class="number">1700.0</span> * weight * <span class="number">14.5833</span>;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Your weight in platinum is worth $%.2f.\n&quot;</span>, value);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;You are easily worth that !If plati...&quot;</span>);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;eat more to maintain your value.\n&quot;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>result：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Are you worth your weight in platinum?</span><br><span class="line">Let&#39;s check it out.</span><br><span class="line">Please enter your weight in pounds:156</span><br><span class="line">Your weight in platinum is worth $3867491.25.</span><br><span class="line">You are easily worth that !If plati...eat more to maintain your value.</span><br></pre></td></tr></table></figure>

<p>程序中的新元素：</p>
<ul>
<li>float 浮点数类型 可以处理更大范围的数据，且可以存储带小数点的数字。</li>
<li>为了打印新类型的变量，在printf()中使用 %f 来处理浮点值，%.2f 中的 .2 用于精确控制输出，指定输出的浮点数只显示小数点后两位。</li>
<li>scanf() 函数用于读取键盘的输入，。%f 说明scanf() 要读取用户从键盘输入的浮点数，&amp;weight 告诉 scanf() 把输入的值赋给名为weight 的变量。&amp; 取地址符。</li>
</ul>
<p><strong><a name="3.2">3.2 变量和常量数据</a></strong></p>
<p>在整个程序运行中没有变化的数据类型就成为常量，反之为变量。</p>
<p><strong><a name="3.3">3.3 数据：数据类型关键字</a></strong></p>
<p>对于变量需要在声明时候指定其类型。</p>
<table>
<thead>
<tr>
<th>最初的数据类型关键字</th>
<th>C90添加的关键字</th>
<th>C99添加的关键字</th>
</tr>
</thead>
<tbody><tr>
<td>int</td>
<td>signed</td>
<td>_Bool</td>
</tr>
<tr>
<td>long</td>
<td>void</td>
<td>_Complex</td>
</tr>
<tr>
<td>short</td>
<td></td>
<td>_Imaginary</td>
</tr>
<tr>
<td>unsigned</td>
<td></td>
<td></td>
</tr>
<tr>
<td>char</td>
<td></td>
<td></td>
</tr>
<tr>
<td>float</td>
<td></td>
<td></td>
</tr>
<tr>
<td>double</td>
<td></td>
<td></td>
</tr>
</tbody></table>
<ul>
<li>int 表示基本的整数类型，后边的3个关键字 long、short、unsigned以及C90新增的signed用于提供基本整数类型的变式，例如，unsigned short int 和 long long int 。</li>
<li>char关键字用于指定字母和其他字符，另外，char类型也可以表示较小的整数。</li>
<li>float、double和long double 表示带小数点的数。</li>
<li>_Bool 表示 true 或 false</li>
<li>_complex 和 _Imaginary 分别表示复数和虚数</li>
</ul>
<p>通过这些关键字创建的类型，按照计算机的存储方式可以分为两大基本类型，整数类型和浮点数类型。</p>
<blockquote>
<p>位、字节、字</p>
<p>8位 = 1 字节</p>
<p>字(word) 是设计计算机是给定的自然存储单位，对于8位的微型计算机，1个字长只有8位。之后的个人计算机字长增至16位、32位，直到目前的64位。计算机的字长越大，其数据转移越快，允许的内存访问也更多。</p>
</blockquote>
<ul>
<li><p>整数</p>
<p>计算机以二进制存储整数，例如7的二进制写是111.因此要在8位字节中存储该数字，需要把前五位都设置为0，后三位设置为1。</p>
</li>
<li><p>浮点数</p>
<p>2.75、3.16E7、7.00、2e-8 都是浮点数。7 是整数，7.00是浮点数，即在一个值后加一个小数点，这个值就是浮点值。浮点数有许多计数方法，主要是e计数法 3.16E7 = 3.16*10^7</p>
</li>
<li><p>浮点数的存储方式</p>
<p>浮点数和整数的存储方案不同，计算机把浮点数分为小数部分和指数部分表示。而且分开存储这两部分，因此虽然7.00和7在数值上相同，但是由于存储方式不同，在十进制下，可以将7.0写成0.7E1。这里的0.7是小数部分，1是指数部分<img src="https://gitee.com/hardychenlong/giteeblogimg/raw/master/20201018111515.png" class="lazyload" data-srcset="https://gitee.com/hardychenlong/giteeblogimg/raw/master/20201018111515.png" srcset="" alt="image-20201018111508669"></p>
</li>
<li><p>整数和浮点数的区别</p>
<ul>
<li>有无小数</li>
<li>浮点数表达范围大于整数</li>
<li>对于相同的算术运算，浮点数损失的精度更多</li>
<li>计算机的浮点数不能表示所有的值，浮点数通常是实际值的近似值，例如，7.0可能被存储为浮点值6.99999</li>
<li>过去的浮点数运算比整数慢，不多由于现在的CPU基本都包含浮点处理器，速度便差不多了。</li>
</ul>
</li>
</ul>
<p>  <strong><a name="3.4">3.4 C语言基本数据类型</a></strong></p>
<ul>
<li><p>int 类型</p>
<p>有符号整型，即int可以有正负，其取值范围根据计算机系统而异，早期的16位PC用16位来存储一个int值，所以它的取值范围为 -32768 ~ 32767，目前的计算机是32/64位，即32/64位存储一个int值，那就更大了。</p>
<p>声明int 类型的整型变量，可以一次声明多个变量，以逗号分隔,最后一分号；结束。</p>
<p>int hogs,cows,goats;</p>
<p>声明后为变量分配内存空间。但是声明后并未给变量提供值。</p>
<p>变量获取值可以通过赋值：</p>
<p>cows = 112;</p>
<p>亦可以通过scanf() 获得值；</p>
<p>还可以初始化变量，就是在声明的时候给变量赋值一个初始值。</p>
<p>int hogs = 21;</p>
<p>最好不要把初始化的变量和未初始化的变量写在一行，容易让人误解。</p>
<ul>
<li><p>打印int值</p>
<p>可以使用printf()打印int类型的值， %d 指明了在一行中打印整数的位置，%d称为转换说明，它指定了printf() 以什么格式来显示一个值。</p>
</li>
<li><p>八进制和十六进制</p>
<p>0x 或0X 前缀表示十六进制值，例如十进制16 表示成十六进制 是 0x10 或0X10</p>
<p>o 前缀表示八进制，例如十进制16 表示八进制是 o20</p>
</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* bases.c -- 以十进制、八进制、十六进制 打印十进制数100*/</span></span><br><span class="line"><span class="meta"># <span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* code */</span></span><br><span class="line">    <span class="keyword">int</span> x = <span class="number">100</span>;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;dec = %d;octal = %o;hex = %x\n&quot;</span>,x,x,x);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;dec = %d;octal = %#o;hex = %#x\n&quot;</span>,x,x,x);</span><br><span class="line">    <span class="comment">// 要显示进制前缀需要在%后加个#</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>result：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dec &#x3D; 100;octal &#x3D; 144;hex &#x3D; 64</span><br><span class="line">dec &#x3D; 100;octal &#x3D; 0144;hex &#x3D; 0x64</span><br></pre></td></tr></table></figure>
</li>
<li><p>其他整数类型</p>
<p>int 类型可以满足大部分程序的整数要求，当然，可以使用C提供的3个附属关键字来修饰基本的整数类型 int 达到int 的变式。</p>
<ul>
<li>short int 类型（或者简写为short）占用的存储空间 可能 比int 的小，适用于较小数值的场合以节省空间。short是有符号类型的，即可正负。</li>
<li>long int（简写 long）占用空间可能比 int  多，但是取值范围更大，且有符号。</li>
<li>long long int （C99标准加入） 占用的空间比long更大，这个类型至少占用64位，也是有符号。</li>
<li>unsigned int （简写 unsigned） 无符号，只有正数，例如16位的 unsigned 其取值范围为 0 ~ 65535，将用于正负号的一位用于表示另一个二进制位，可以表达更大的数。</li>
<li>在任何有符号类型面前添加关键字 signed ，可以强调有符号类型的意图；例如 short 和 signed short 是同一种类型。</li>
<li>C99 新加了 long long ,不是所有的编译器都支持。</li>
</ul>
</li>
<li><p>使用多种整数类型的原因</p>
<p>C语言只是规定了short 所占空间不能多于int，long占用空间不少于int，这样规定是为了适应不同的机器。移植时候可能也要注意其数据类型的取值范围。如果在long和int类型占用相同空间的机器上编码，应使用long，以便之后移植到16位机器后也可以正常使用。</p>
</li>
<li><p>打印short、long、long long 和unsigned 类型</p>
<p>打印unsigned int 使用 %u转换说明，打印long类型，使用%ld，如果系统的long和int大小相同，使用%d即可。在x和o前可以使用l前缀，%lx表示以十六进制格式打印long类型整数，%lo表示八进制格式打印long类型整数。注意在转换说明中的x和o只能使用小写。</p>
<p>对于short可以使用%h表示，%ho表示以八进制显示short类型的整数。，l 和 h 前缀都可以和 u一起使用。例如，%lu 表示打印 unsigned long 类型的值。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* print2.c -- 更多printf()特性 */</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* code */</span></span><br><span class="line">    <span class="keyword">unsigned</span> <span class="keyword">int</span> un = <span class="number">300000000</span>; <span class="comment">/* int 为32位和short为16位的系统*/</span></span><br><span class="line">    <span class="keyword">short</span> end = <span class="number">200</span>;</span><br><span class="line">    <span class="keyword">long</span> big = <span class="number">65537</span>;</span><br><span class="line">    <span class="keyword">long</span> <span class="keyword">long</span> verybig = <span class="number">12345678908642</span>;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;un = %u and not %d\n&quot;</span>,un,un);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;end = %hd and %d\n&quot;</span>,end,end);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;big = %ld and not %hd\n&quot;</span>,big,big);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;verybig = %lld and not %ld\n&quot;</span>,verybig,verybig);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>result:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">un &#x3D; 300000000 and not 300000000</span><br><span class="line">end &#x3D; 200 and 200</span><br><span class="line">big &#x3D; 65537 and not 1</span><br><span class="line">verybig &#x3D; 12345678908642 and not 1942899938</span><br></pre></td></tr></table></figure>

<p>对于第二行输出，在printf()中无论指定以short还是int类型打印，其打印出的值都是相同的。因为在给函数传递参数时，编译器将short的值自动转化为int类型的值，因为int被计算机认为是处理整数类型最高效的类型。那这个%h 修饰符作用是为了显示较大的整数被截断成short的情况，第三行的输出就是这种情况。65537 若使用%hd就只会查看其后16位，刚好只有一个1，第十七位的1没转化过来。最后一行也是如此情况，%ld只显示最后32位的值。</p>
<blockquote>
<p>使用printf() 函数时，要注意检查每个待打印的值都有对应的转换说明以及转换说明的类型是否与被打印的值的类型相匹配。</p>
</blockquote>
</li>
<li><p>使用字符：char类型</p>
<p>char类型用于存储字符，但是char是整数类型，因为char类型实际上存储的是整数而不是字符，计算机使用数字编码来处理字符，一般是ASCII编码，例如65表示A，97表示a。</p>
<p>C语言将1字节定义为char类型所占用的位数。</p>
<ul>
<li><p>声明char类型，和声明其他类型变量一样。</p>
</li>
<li><p>字符常量和初始化</p>
<p>char grade = ‘A’;</p>
<p>用单引号括起来的单个字符称为字符常量。编译器一发现’A’ 就会将其转换为对应的代码值，所以单引号必不可少。</p>
<p>双引号括起来的是字符串，以下写法是错误的。</p>
<p>char grade = “A”;</p>
<p>双引号括起来的编译器会认为是字符串。</p>
<p>实际上，字符以数值的形式存储，所以亦可以用数字代替字母来赋值。但是不推荐。</p>
<p>值得注意的是C语言将char类型视为int来存储值，例如：</p>
<p>char grade = ‘FATE’;</p>
<p>其将4个独立的8位ASCII码存储在一个32位的存储单元中，如果这样赋值，只有最后八位有效，所以grade的值是’E’。</p>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>非打印字符</p>
<p>有些特殊字符打印不出来，有以下3中方法：</p>
<ul>
<li>使用ASCII码 char beep = 7;</li>
<li>使用转移字符\ ，即转椅序列，把转义序列赋值给字符变量时，需要用单引号将其括起来， char nerf = ‘\n’;<br>\a 警报；\b 退格； \f 换页；\n 换行；\r 回车；\t 制表符；\ \ 反斜杠；\“ 双引号；<br>? 问好；\o00 八进制值；\xhh 十六进制； </li>
</ul>
<p>C90开始，不仅可以使用十进制、八进制表示字符常量，还可以使用十六进制表示字符常量。<br>字符串内的转义序列无需使用单引号括起来。</p>
</li>
<li><p>打印字符</p>
<p>可以用%d和%c打印字符对应的整数和字符。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* charcode.c -- 显示字符的代码编号*/</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* code */</span></span><br><span class="line">    <span class="keyword">char</span> ch;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Please enter a character.\n&quot;</span>);</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%c&quot;</span>,&amp;ch);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;The code for %c is %d.\n&quot;</span>,ch,ch);</span><br><span class="line">    getchar();</span><br><span class="line">    getchar();</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>result：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Please enter a character.</span><br><span class="line">C</span><br><span class="line">The code for C is 67.</span><br></pre></td></tr></table></figure>

<p>注意printf() 函数里面的转换说明决定了数据的显示方式，而不是数据的存储方式。</p>
</li>
<li><p>有些编译器把char类型实现为有符号类型，有些又是无符号类型，其取值范围不同，使用时应查看对应的编译器手册，确定编译器使用的char类型，或者查看limits.h 头文件。<br>根据C90标准，C语言允许在关键字char前使用signed或unsigned，这样，无论编译器默认char是什么类型，可以自己规定有无符号的char类型，在使用从char表示处理小整数时很有用，但是如果只用char处理字符，就需要在char前面添加任何修饰符。</p>
</li>
</ul>
<ul>
<li><p>_Bool 类型</p>
<p>C99添加了_Bool 类型，用于表示布尔值，true 和 false，C语言使用1表示true，0表示false，所以 _Bool 实际上也是一种整数类型，但是其原则上只占用1位的存储空间。</p>
</li>
</ul>
<ul>
<li><p>可移植类型：stdint.h 和 inttypes.h</p>
<p>C99 新增加两个头文件stdint.h 和 inttypes.h，便于移植时确保C语言的类型在不同系统的功能相同。在包含头文件stdint.h 头文件时，编译器会把int或long根据系统位数类匹配。</p>
<p>C99和C11不仅提供可移植的类型名，还提供对应的输入和输出，如果要打印int32_t 类型的值，有些定义使用%d，有些使用%ld ，为了应对这种情况，C提供了PRId32字符串宏在inttypes.h 头文件中，代表打印32位有符号值的合适转换说明（如d或l）</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* altnames.c -- 可移植整数类型名*/</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;inttypes.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* code */</span></span><br><span class="line">    <span class="keyword">int32_t</span> me32;</span><br><span class="line">    me32 = <span class="number">45933945</span>;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;First,assume int32_t is int:&quot;</span>);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;me32 = %d\n&quot;</span>,me32);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Next,let&#x27;s not make any assumptions.\n&quot;</span>);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Instead,use a \&quot;macro\&quot; from inttypes.h:&quot;</span>);</span><br><span class="line">    <span class="comment">// printf(&quot;me32=%&quot; PRId32 &quot;\n&quot;,me32);</span></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;me32=%&quot;</span> <span class="string">&quot;d&quot;</span> <span class="string">&quot;\n&quot;</span>,me32);</span><br><span class="line">    getchar();</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>result</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">First,assume int32_t is int:me32 &#x3D; 45933945</span><br><span class="line">Next,let&#39;s not make any assumptions.</span><br><span class="line">Instead,use a &quot;macro&quot; from inttypes.h:me32&#x3D;45933945</span><br></pre></td></tr></table></figure>
</li>
<li><p>float、double、和long double</p>
<p>C标准规定，float类型必须至少能表示6位有效数字，即至少精确到小数点后六位；一般系统存储一个浮点数要占用32位，其中8位用于表示指数的值和符号，剩下24位用于表示非指数部分及其符号。<br>C语言提供的另一种浮点类型是double（双精度），double和float类型的最小取值范围相同，且至少需要能表示10位有效数字。一般情况下double占用64位，将比float多出的32位用于表示非指数部分，增加了有效位数以及减少了舍入误差。</p>
</li>
<li><p>声明浮点型常量</p>
<p>在代码中可以使用多种形式书写浮点型变量，浮点型变量的基本形式是：有符号的数字（包含小数点）后面紧跟e或者E，最后一个是有符号数表示10的指数。例如：<br>-1.56E+12<br>2.87e-3<br><strong>其中正号可以省略，小数点也可以省略例如（2E5）或省略指数部分,就是习惯写的小数形式(2.0)，但是这两种形式不可以同时使用，即不可以同时省略小数点和指数部分。</strong><br><strong>当然也可以省略小数部分例如（3.E16）或者省略整数部分（.45E-6）但也是不能同时省略,即e前需要有数值。</strong></p>
<p>需要注意的是不能再浮点型常量中间加空格。</p>
<p>默认情况下编译器假定浮点型常量是double类型的精度，例如：</p>
<p>some = 4.0 * 2.0;</p>
<p>通常，4.0和2.0被存储为64位的double类型，使用双精度进行乘法运算，然后将乘积截断成float类型的宽度，虽然计算的精度高，但是会减慢程序运行的速度。</p>
<p>在浮点数后面加上f或者F后缀可以覆盖默认的设置，编译器会将浮点型常量看做float类型，例如2.3f和9.11E9F。使用 l  或 L 后缀使得数字成为 long double 类型，如 54.3l 和 4.32L。这里建议使用L后缀，因为英文 l 和数字 1 比较容易弄混淆。没有后缀的浮点数常量是double 类型。</p>
<p>C99 又添加了 十六进制表示浮点数常量，即在十六进制数前加上十六进制前缀0x，用p或P代替e或E，用2的幂代替10的幂（即 p计数法），例如： </p>
<p><strong>0xa.1fp10</strong></p>
<p>其中a表示十六进制的 10 ，.1f 是 1/16 加上 15/256 （十六进制f等于15），p10是2^10 或1024。</p>
<p>注意，并不是所有的C99都支持这一特性。</p>
</li>
<li><p>打印浮点值</p>
<p>printf() 函数使用%f 转换说明 打印十进制记数法的 float 和double 类型浮点数，用%e打印指数记数法的浮点数，如果系统支持C99的十六进制浮点数可以用a或A代替e和E，打印long double 时候要使用%Lf、%Le或%La转换说明。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* showf_pt.c -- 以两种方式显示float 类型的值*/</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* code */</span></span><br><span class="line">    <span class="keyword">float</span> aboat = <span class="number">32000.0</span>;</span><br><span class="line">    <span class="keyword">double</span> abet = <span class="number">2.14e9</span>;</span><br><span class="line">    <span class="keyword">long</span> <span class="keyword">double</span> dip = <span class="number">5.32e-5</span>;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;%f can be written %e\n&quot;</span>,aboat,aboat);</span><br><span class="line">    <span class="comment">// 下一行要求编译器支持C99的新特性十六进制表示浮点数</span></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;And it&#x27;s %a in hexadecimal ,power of 2 notation.\n&quot;</span>,aboat);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;%f can be written %e\n&quot;</span>,abet,abet);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;%Lf can be written %Le\n&quot;</span>,dip,dip);</span><br><span class="line">    getchar();</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>result：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">32000.000000 can be written 3.200000e+004</span><br><span class="line">And it&#39;s 0x1.f40000p+14 in hexadecimal ,power of 2 notation.</span><br><span class="line">2140000000.000000 can be written 2.140000e+009</span><br><span class="line">0.000000 can be written 3.172882e-317</span><br></pre></td></tr></table></figure>

<blockquote>
<p>tips：浮点数的舍入错误</p>
<p>给定一个数，加上1，再减去原来给定的数，结果不一定是1，因为有些数计算机缺少位数来运算，其计算结果一定是错误的。</p>
</blockquote>
</li>
<li><p>复数和虚数类型</p>
<p>C99标准支持复数和虚数类型，C11标准将整个复数软件包作为可选项。</p>
<p>C语言由3种复数类型：float_Complex 、double_Complex和 long double _Complex。例如float _Complex 类型的变量应当包含两个float 类型的值，分别表示复数的实部和虚部。类似的，C语言也有3种虚数类型：float _Imaginary、double _Imaginary 和 long double _Imaginary<br>有专门的的复数头文件 complex.h </p>
</li>
<li><p>其他类型</p>
<p>C语言虽然没有字符串类型，但是也刻意很好的处理字符串（doge）。C语言还有一些从基本类型衍生的其他类型，如数组、指针、结构和联合。</p>
<blockquote>
<p>tips：scanf() 函数中用到的前缀 &amp; 便创建了一个指针，告诉scanf() 把数据放在何处。</p>
<p>int 不小于16位</p>
<p>short或short int 至少占16位，比int小或等于</p>
<p>long或long int 至少占32位</p>
<p>long long 至少占64位</p>
</blockquote>
</li>
<li><p>类型大小</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* typesize.c -- 打印类型大小*/</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* code */</span></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Type int size: %zd bytes.\n&quot;</span>,<span class="keyword">sizeof</span>(<span class="keyword">int</span>));</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Type char size: %zd bytes.\n&quot;</span>,<span class="keyword">sizeof</span>(<span class="keyword">char</span>));</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Type short size: %zd bytes.\n&quot;</span>,<span class="keyword">sizeof</span>(<span class="keyword">short</span>));</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Type long size: %zd bytes.\n&quot;</span>,<span class="keyword">sizeof</span>(<span class="keyword">long</span>));</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Type long long size: %zd bytes.\n&quot;</span>,<span class="keyword">sizeof</span>(<span class="keyword">long</span> <span class="keyword">long</span>));</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Type double size: %zd bytes.\n&quot;</span>,<span class="keyword">sizeof</span>(<span class="keyword">double</span>));</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;Type long double size: %zd bytes.\n&quot;</span>,<span class="keyword">sizeof</span>(<span class="keyword">long</span> <span class="keyword">double</span>));</span><br><span class="line">    getchar();</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>result：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Type int size: 4 bytes.</span><br><span class="line">Type char size: 1 bytes.</span><br><span class="line">Type short size: 2 bytes.</span><br><span class="line">Type long size: 4 bytes.</span><br><span class="line">Type long long size: 8 bytes.</span><br><span class="line">Type double size: 8 bytes.</span><br><span class="line">Type long double size: 16 bytes.</span><br></pre></td></tr></table></figure>

<p><strong><a name="3.5">3.5 使用数据类型</a></strong></p>
<p>使用变量前需要先声明并选择有意义的变量名。有一些规定的系统化的命名约定，在变量名中体现其类型，用 i_ 前缀表示 int 类型，us_ 表示 unsigned short 。</p>
<p><strong><a name="3.6">3.6 参数和陷阱</a></strong></p>
<p>printf()函数字符串为一个参数，scanf(“%d”,&amp;weight)  有两个参数。 printf() 和scanf() 函数的参数个数是可变的，参数个数和第一个参数的转换说明个数要对应。</p>
<p><strong><a name="3.7">3.7 转义序列示例</a></strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*escape.c -- 使用转义序列*/</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> <span class="keyword">const</span> *argv[])</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* code */</span></span><br><span class="line">    <span class="keyword">float</span> salary;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\aEnter your desired monthly salary:&quot;</span>);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;$_______\b\b\b\b\b\b\b&quot;</span>);</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%f&quot;</span>,&amp;salary);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\n\t$%.2f a month is $%.2f a year.&quot;</span>,salary,salary*<span class="number">12.0</span>);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\rGee!\n&quot;</span>);</span><br><span class="line">    getchar();</span><br><span class="line">    getchar();</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>result</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Enter your desired monthly salary:$_______</span><br><span class="line">Enter your desired monthly salary:$4000.00</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Enter your desired monthly salary:$4000.00</span><br><span class="line"></span><br><span class="line">        $4000.00 a month is $48000.00 a year.</span><br></pre></td></tr></table></figure>



</li>
</ul>
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Enter your desired monthly salary:$4000.00</span><br><span class="line"></span><br><span class="line">Gee!    $4000.00 a month is $48000.00 a year.</span><br></pre></td></tr></table></figure>

<p>  首先 \a 发出一声警报，光标在冒号后面：输入的字符替换了下划线字符，按下enter后光标移至下一行，输出第二个printf后光标在最后，然后 \r 让光标返回当前行的开头/起始处，接着 \n 使得光标移动到下一行的起始处。</p>
<ul>
<li><p>刷新输出</p>
<p>一开始，printf() 语句会把语句输出发送到 <strong>缓冲区</strong> 的中间存储区域，然后缓冲区中的内容不断被发送到屏幕上，C标准明确了何时把缓冲区的内容发送到屏幕中：当缓冲区满了，遇到换行字符或需要输入时（从缓冲区把数据发送到屏幕或文件称为刷新缓冲区）。也可以使用 fflush() 函数刷新缓冲区。</p>
</li>
</ul>
<p><strong><a name="3.8">3.8 关键概念</a></strong></p>
<p>计算机的浮点数和整数在本质上不同，其存储方式和运算过程有很大区别，即使两个32位存储单元的存储的位组合完全相同，但是一个解释为float，另一个解释为long，这两个相同位组合表示的值也完全不同。例如，假设一个位组合表示的float的数为256.0，如果将其解释为long 得到的值是113246208。</p>
<p><strong><a name="3.9">3.9 本章小结</a></strong></p>
<p>C的基本数据类型分为两大类整数类型和浮点数类型。最小的整数类型为char，注意char可以是有符号的char。浮点类型有3种，float、double以及C90新加的long double。浮点数可以写成固定小数点的形式（9393.912）或指数形式（7.38E10）。C99和C11新提供了十六进制和2的幂表示。<br>printf() 根据转换说明来打印对应的值。</p>
<p><strong><a name="3.10">3.10 复习题</a></strong></p>
<p>使用 int32_t 作为标准的32位整型数据， int_least32_t 获得至少32位整型数据，int_fast32_t 获得32整型数据的最快计算速度。</p>
<p>’\b‘ 表示转义的 退格</p>
<p>0xAA 表示十六进制 unsigned int 数据类型，对于八进制和十六进制系统优先解释为无符号类型。</p>
<p>2.0e30 表示双精度浮点类型数据常量，虽然改值没有超过float 的取值范围，但是编译器默认将浮点型常量统一为double类型，除非自定义为float类型，在其后边加个f或F表示为float。</p>
<p>使用e指数表示浮点数时，注意e前要有数值。以下写法<strong>错误</strong></p>
<p>g = e12;</p>
<p>正确应该是：</p>
<p>g = 1e12; 或者 g = 1.0e12;  (小数点)</p>
<table>
<thead>
<tr>
<th>常量</th>
<th>类型</th>
<th>转换说明符</th>
</tr>
</thead>
<tbody><tr>
<td>12</td>
<td>int</td>
<td>%d</td>
</tr>
<tr>
<td>0X3</td>
<td>unsigned int</td>
<td>%#X</td>
</tr>
<tr>
<td>‘C’</td>
<td>char</td>
<td>%c</td>
</tr>
<tr>
<td>2.34E07</td>
<td>double</td>
<td>%e</td>
</tr>
<tr>
<td>‘\040’</td>
<td>char</td>
<td>%c</td>
</tr>
<tr>
<td>7.0</td>
<td>double(编译器默认)</td>
<td>%f</td>
</tr>
<tr>
<td>6L</td>
<td>long (int)</td>
<td>%ld</td>
</tr>
<tr>
<td>6.0f</td>
<td>float</td>
<td>%f</td>
</tr>
<tr>
<td>0x5.b6p12</td>
<td>float (c99/c11 p记数法)</td>
<td>%a</td>
</tr>
<tr>
<td>o12</td>
<td>unsigned int</td>
<td>%#o</td>
</tr>
<tr>
<td>2.9e05L</td>
<td>long double(long和e指数的组合)</td>
<td>%Le</td>
</tr>
<tr>
<td>100000</td>
<td>long</td>
<td>%ld</td>
</tr>
<tr>
<td>‘\n’</td>
<td>char</td>
<td>%c</td>
</tr>
</tbody></table>
<p>赋值回车符给ch变量的几种方式</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">char ch &#x3D; &#39;\r&#39;;</span><br><span class="line">char ch &#x3D; 13;</span><br><span class="line">char ch &#x3D; &#39;\o15&#39;;</span><br><span class="line">char ch &#x3D; &#39;\xd&#39;;</span><br></pre></td></tr></table></figure>

<p>scanf() 函数给变量赋值时记得 &amp;</p>
<p><strong><a name="3.11">3.11 编程练习</a></strong></p>

  
  
    
    <div class='footer'>
      
      
      
        <div class='copyright'>
          <blockquote>
            
              
                <p>博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议</p>

              
            
              
                <p>本文永久链接是：<a href=https://hardydragon.gitee.io/blog/2021/03/22/%E7%AC%AC%E4%B8%89%E7%AB%A0%E6%95%B0%E6%8D%AE%E5%92%8CC/>https://hardydragon.gitee.io/blog/2021/03/22/%E7%AC%AC%E4%B8%89%E7%AB%A0%E6%95%B0%E6%8D%AE%E5%92%8CC/</a></p>
              
            
          </blockquote>
        </div>
      
      
    </div>
  
  
    


  <div class='article-meta' id="bottom">
    <div class='new-meta-box'>
      
        
          <div class="new-meta-item date" itemprop="dateUpdated" datetime="2021-03-22T22:59:30+08:00">
  <a class='notlink'>
    <i class="fas fa-edit fa-fw" aria-hidden="true"></i>
    <p>更新于：2021年3月22日</p>
  </a>
</div>

        
      
        
          
  
  <div class="new-meta-item meta-tags"><a class="tag" href="/blog/tags/C-Notes/" rel="nofollow"><i class="fas fa-hashtag fa-fw" aria-hidden="true"></i><p>C Notes</p></a></div>


        
      
        
          
  <div class="new-meta-item share -mob-share-list">
  <div class="-mob-share-list share-body">
    
      
        <a class="-mob-share-qq" title="" rel="external nofollow noopener noreferrer noopener"
          
          target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://hardydragon.gitee.io/blog/2021/03/22/%E7%AC%AC%E4%B8%89%E7%AB%A0%E6%95%B0%E6%8D%AE%E5%92%8CC/&title=第三章 数据和C - HardyDragon Index&summary="
          
          >
          
            <img src="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/logo/128/qq.png" class="lazyload" data-srcset="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/logo/128/qq.png" srcset="">
          
        </a>
      
    
      
        <a class="-mob-share-qzone" title="" rel="external nofollow noopener noreferrer noopener"
          
          target="_blank" href="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=https://hardydragon.gitee.io/blog/2021/03/22/%E7%AC%AC%E4%B8%89%E7%AB%A0%E6%95%B0%E6%8D%AE%E5%92%8CC/&title=第三章 数据和C - HardyDragon Index&summary="
          
          >
          
            <img src="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/logo/128/qzone.png" class="lazyload" data-srcset="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/logo/128/qzone.png" srcset="">
          
        </a>
      
    
      
        <a class="-mob-share-weibo" title="" rel="external nofollow noopener noreferrer noopener"
          
          target="_blank" href="http://service.weibo.com/share/share.php?url=https://hardydragon.gitee.io/blog/2021/03/22/%E7%AC%AC%E4%B8%89%E7%AB%A0%E6%95%B0%E6%8D%AE%E5%92%8CC/&title=第三章 数据和C - HardyDragon Index&summary="
          
          >
          
            <img src="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/logo/128/weibo.png" class="lazyload" data-srcset="https://cdn.jsdelivr.net/gh/volantis-x/cdn-org/logo/128/weibo.png" srcset="">
          
        </a>
      
    
      
    
      
    
  </div>
</div>



        
      
    </div>
  </div>


  
  

  
    <div class="prev-next">
      
        <a class='prev' href='/blog/2021/03/22/%E7%AC%AC%E4%B8%83%E7%AB%A0C%E6%8E%A7%E5%88%B6%E8%AF%AD%E5%8F%A5%E5%88%86%E6%94%AF%E5%92%8C%E8%B7%B3%E8%BD%AC/'>
          <p class='title'><i class="fas fa-chevron-left" aria-hidden="true"></i>第七章 C控制语句：分支和跳转</p>
          <p class='content'>第七章 C控制语句：分支和跳转7.1 if语句7.2 if else语句7.2.1 介绍getchar()7.2.2 ctype.h 系列的字符函数7.2.3 多重选择else if7.2.4 ...</p>
        </a>
      
      
        <a class='next' href='/blog/2020/11/01/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0%E6%89%8B%E5%86%99%E6%95%B0%E5%AD%97%E3%80%81%E7%8C%AB%E7%8B%97%E3%80%81%E7%9F%B3%E5%A4%B4%E5%89%AA%E5%88%80%E5%B8%83%E8%AF%86%E5%88%AB/'>
          <p class='title'>keras深度学习手写数字、猫狗、石头剪刀布识别<i class="fas fa-chevron-right" aria-hidden="true"></i></p>
          <p class='content'>使用keras搭建简单的CNN网络训练流程：
数据预处理，生成x、y训练集np数组
搭建神经网络 Sequential()
compile 配置训练参数
将x、y数组扔去网络里 fit训练，指定...</p>
        </a>
      
    </div>
  
</article>


  

  <article class="post white-box reveal shadow" id="comments">
    <p ct><i class='fas fa-comments'></i> 评论</p>
    
    <div id="valine_container" class="valine_thread">
  <i class="fas fa-cog fa-spin fa-fw fa-2x"></i>
</div>

  </article>






</div>
<aside class='l_side'>
  
  
    
    



  <section class="widget toc-wrapper shadow desktop mobile" id="toc-div" >
    
  <header>
    
      <i class="fas fa-list fa-fw" aria-hidden="true"></i><span class='name'>本文目录</span>
    
  </header>


    <div class='content'>
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1-%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F"><span class="toc-text">3.1 示例程序</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2-%E5%8F%98%E9%87%8F%E5%92%8C%E5%B8%B8%E9%87%8F%E6%95%B0%E6%8D%AE"><span class="toc-text">3.2 变量和常量数据</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-3-%E6%95%B0%E6%8D%AE%EF%BC%9A%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-text">3.3 数据：数据类型关键字</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-1-%E6%95%B4%E6%95%B0%E5%92%8C%E6%B5%AE%E7%82%B9%E6%95%B0"><span class="toc-text">3.3.1 整数和浮点数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-2-%E6%95%B4%E6%95%B0"><span class="toc-text">3.3.2 整数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-3-%E6%B5%AE%E7%82%B9%E6%95%B0"><span class="toc-text">3.3.3 浮点数</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-4-C%E8%AF%AD%E8%A8%80%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-text">3.4 C语言基本数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#int%E7%B1%BB%E5%9E%8B"><span class="toc-text">int类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-text">其他数据类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E5%85%B6%E4%BB%96%E5%AD%97%E7%AC%A6%EF%BC%9Achar%E7%B1%BB%E5%9E%8B"><span class="toc-text">使用其他字符：char类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Bool%E7%B1%BB%E5%9E%8B"><span class="toc-text">_Bool类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%AF%E7%A7%BB%E6%A4%8D%E7%B1%BB%E5%9E%8B%EF%BC%9Astdint-h%E5%92%8Cinttypes-h"><span class="toc-text">可移植类型：stdint.h和inttypes.h</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#float%E3%80%81double%E3%80%81%E5%92%8Clong%E3%80%81double"><span class="toc-text">float、double、和long、double</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%8D%E6%95%B0%E5%92%8C%E8%99%9A%E6%95%B0%E7%B1%BB%E5%9E%8B"><span class="toc-text">复数和虚数类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E7%B1%BB%E5%9E%8B"><span class="toc-text">其他类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B1%BB%E5%9E%8B%E5%A4%A7%E5%B0%8F"><span class="toc-text">类型大小</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-5-%E4%BD%BF%E7%94%A8%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-text">3.5 使用数据类型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-6-%E5%8F%82%E6%95%B0%E5%92%8C%E9%99%B7%E9%98%B1"><span class="toc-text">3.6 参数和陷阱</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-7-%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97%E7%A4%BA%E4%BE%8B"><span class="toc-text">3.7 转义序列示例</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-7-1-%E7%A8%8B%E5%BA%8F%E8%BF%90%E8%A1%8C%E6%83%85%E5%86%B5"><span class="toc-text">3.7.1 程序运行情况</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-7-2-%E5%88%B7%E6%96%B0%E8%BE%93%E5%87%BA"><span class="toc-text">3.7.2 刷新输出</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-8-%E5%85%B3%E9%94%AE%E6%A6%82%E5%BF%B5"><span class="toc-text">3.8 关键概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-9-%E6%9C%AC%E7%AB%A0%E5%B0%8F%E7%BB%93"><span class="toc-text">3.9 本章小结</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-10-%E5%A4%8D%E4%B9%A0%E9%A2%98"><span class="toc-text">3.10 复习题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-11-%E7%BC%96%E7%A8%8B%E7%BB%83%E4%B9%A0"><span class="toc-text">3.11 编程练习</span></a></li></ol>
    </div>
  </section>


  


</aside>



        
      </div>
      
  
  <footer class="footer clearfix">
    <br><br>
    
      
        <div class="aplayer-container">
          

  
    <meting-js
      theme='#1BCDFC'
      autoplay='false'
      volume='0.7'
      loop='all'
      order='list'
      fixed='true'
      list-max-height='320px'
      server='netease'
      type='playlist'
      id='3175833810'
      list-folded='true'>
    </meting-js>
  


        </div>
      
    
      
        <br>
        <div class="social-wrapper">
          
            
          
            
          
            
              <a href="https://gitee.com/hardychenlong"
                class="social fab fa-gitee flat-btn"
                target="_blank"
                rel="external nofollow noopener noreferrer">
                
              </a>
            
          
            
          
        </div>
      
    
      
        <div><p>博客内容遵循 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议</a></p>
</div>
      
    
      
        本站使用
        <a href="https://github.com/volantis-x/hexo-theme-volantis/tree/4.0.0" target="_blank" class="codename">Volantis</a>
        作为主题
      
    
      
        <div class='copyright'>
        <p><a target="_blank" rel="noopener" href="https://hardydragon.io/">Copyright © 2020-2021 HardyDragon</a></p>

        </div>
      
    
  </footer>


      <a class="s-top fas fa-arrow-up fa-fw" href='javascript:void(0)'></a>
    </div>
  </div>
  <div>
    <!-- required -->

<script src="https://cdn.jsdelivr.net/npm/jquery@3.5/dist/jquery.min.js"></script>

<script>
  function pjax_fancybox() {
    $(".md .gallery").find("img").each(function () { //渲染 fancybox
      var element = document.createElement("a"); // a 标签
      $(element).attr("class", "fancybox");
      $(element).attr("pjax-fancybox", "");  // 过滤 pjax
      $(element).attr("href", $(this).attr("src"));
      if ($(this).attr("data-original")) {
        $(element).attr("href", $(this).attr("data-original"));
      }
      $(element).attr("data-fancybox", "images");
      var caption = "";   // 描述信息
      if ($(this).attr('alt')) {  // 判断当前页面是否存在描述信息
        $(element).attr('data-caption', $(this).attr('alt'));
        caption = $(this).attr('alt');
      }
      var div = document.createElement("div");
      $(div).addClass("fancybox");
      $(this).wrap(div); // 最外层套 div ，其实主要作用还是 class 样式
      var span = document.createElement("span");
      $(span).addClass("image-caption");
      $(span).text(caption); // 加描述
      $(this).after(span);  // 再套一层描述
      $(this).wrap(element);  // 最后套 a 标签
    })
    $(".md .gallery").find("img").fancybox({
      selector: '[data-fancybox="images"]',
      hash: false,
      loop: false,
      closeClick: true,
      helpers: {
        overlay: {closeClick: true}
      },
      buttons: [
        "zoom",
        "close"
      ]
    });
  };
  function SCload_fancybox() {
    if ($(".md .gallery").find("img").length == 0) return;
    loadCSS("https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css", document.getElementById("loadcss"));
    setTimeout(function() {
      loadScript('https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js', pjax_fancybox)
    }, 1);
  };
  $(function () {
    SCload_fancybox();
  });
</script>


<!-- internal -->

  
  
  
    
<script src="https://cdn.jsdelivr.net/npm/jquery-backstretch@2.1.18/jquery.backstretch.min.js"></script>

    <script type="text/javascript">
      $(function(){
        var imgs=["https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/001.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/002.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/003.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/004.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/005.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/006.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/012.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/016.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/019.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/025.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/033.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/034.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/035.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/038.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/039.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/042.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/046.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/051.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/052.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/054.jpg", "https://cdn.jsdelivr.net/gh/volantis-x/cdn-wallpaper-minimalist/2020/056.jpg"];
        if ('true' == 'true') {
          function shuffle(arr){
            /*From countercurrent-time*/
            var n = arr.length;
            while(n--) {
              var index = Math.floor(Math.random() * n);
              var temp = arr[index];
              arr[index] = arr[n];
              arr[n] = temp;
            }
          }
          shuffle(imgs);
        }
        if ('.cover-backstretch') {
          $('.cover-backstretch').backstretch(
            imgs,
          {
            duration: "10000",
            fade: "1500"
          });
        } else {
          $.backstretch(
            imgs,
          {
            duration: "10000",
            fade: "1500"
          });
        }
      });
    </script>
  







  <script defer src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.1.0/dist/lazyload.min.js"></script>
<script>
  // https://www.npmjs.com/package/vanilla-lazyload
  // Set the options globally
  // to make LazyLoad self-initialize
  window.lazyLoadOptions = {
    elements_selector: ".lazyload",
    threshold: 0
  };
  // Listen to the initialization event
  // and get the instance of LazyLoad
  window.addEventListener(
    "LazyLoad::Initialized",
    function (event) {
      window.lazyLoadInstance = event.detail.instance;
    },
    false
  );
  document.addEventListener('DOMContentLoaded', function () {
    lazyLoadInstance.update();
  });
  document.addEventListener('pjax:complete', function () {
    lazyLoadInstance.update();
  });
</script>




  
  
    <script>
      window.FPConfig = {
        delay: 0,
        ignoreKeywords: [],
        maxRPS: 5,
        hoverDelay: 25
      };
    </script>
    <script defer src="https://cdn.jsdelivr.net/gh/gijo-varghese/flying-pages@2.1.2/flying-pages.min.js"></script>
  




  <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
    var clipboard = new ClipboardJS('.btn-copy', {
        target: function (trigger) {
            return trigger.nextElementSibling
        }
    });
    function wait(callback, seconds) {
        var timelag = null;
        timelag = window.setTimeout(callback, seconds)
    }
    function pjax_initCopyCode() {
		if($(".highlight .code pre").length+$(".article pre code").length==0)return;
        var copyHtml = '';
        copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
        copyHtml += '<i class="fas fa-copy"></i><span>COPY</span>';
        copyHtml += '</button>';
        $(".highlight .code pre").before(copyHtml);
        $(".article pre code").before(copyHtml);
        clipboard.off('success').on('success', function (e) {
            let $btn = $(e.trigger);
            $btn.addClass('copied');
            let $icon = $($btn.find('i'));
            $icon.removeClass('fa-copy');
            $icon.addClass('fa-check-circle');
            let $span = $($btn.find('span'));
            $span[0].innerText = 'COPIED';
            wait(function () {
                $icon.removeClass('fa-check-circle');
                $icon.addClass('fa-copy');
                $span[0].innerText = 'COPY'
            }, 2000)
        });
        clipboard.off('error').on('error', function (e) {
            e.clearSelection();
            let $btn = $(e.trigger);
            $btn.addClass('copy-failed');
            let $icon = $($btn.find('i'));
            $icon.removeClass('fa-copy');
            $icon.addClass('fa-times-circle');
            let $span = $($btn.find('span'));
            $span[0].innerText = 'COPY FAILED';
            wait(function () {
                $icon.removeClass('fa-times-circle');
                $icon.addClass('fa-copy');
                $span[0].innerText = 'COPY'
            }, 2000)
        })
    }
    $(function () {
        pjax_initCopyCode()
    });
</script>




   <script src="https://cdn.jsdelivr.net/npm/scrollreveal@4.0.6/dist/scrollreveal.min.js"></script>
<script type="text/javascript">
  function pjax_scrollrebeal() {
    ScrollReveal().reveal('.l_main .reveal', {
      distance: '32px',
      duration: '800',
      interval: '20',
      scale: '1',
      easing: 'ease-out'
    });
  }
  $(function () {
    pjax_scrollrebeal();
  });
</script>




  <script>
  let APlayerController = new Object();
  APlayerController.id = '3175833810';  // 设定全局音乐播放ID
  APlayerController.volume = '0.7';
</script>

  
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10/dist/APlayer.min.js"></script>


  
<script src="https://cdn.jsdelivr.net/npm/meting@2.0/dist/Meting.min.js"></script>








  
  
<script src="/blog/js/valine.js"></script>


<script>
  var GUEST_INFO = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link'.split(',').filter(function (item) {
    return GUEST_INFO.indexOf(item) > -1
  });
  var REQUIRED_FIELDS = ['nick', 'mail', 'link'];
  var requiredFields = 'nick,mail'.split(',').filter(function (item) {
    return REQUIRED_FIELDS.indexOf(item) > -1
  });

  function emoji(path, idx, ext) {
    return path + "/" + path + "-" + idx + "." + ext;
  }

  var emojiMaps = {};
  for (var i = 1; i <= 54; i++) {
    emojiMaps['tieba-' + i] = emoji('tieba', i, 'png');
  }
  for (var i = 1; i <= 101; i++) {
    emojiMaps['qq-' + i] = emoji('qq', i, 'gif');
  }
  for (var i = 1; i <= 116; i++) {
    emojiMaps['aru-' + i] = emoji('aru', i, 'gif');
  }
  for (var i = 1; i <= 125; i++) {
    emojiMaps['twemoji-' + i] = emoji('twemoji', i, 'png');
  }
  for (var i = 1; i <= 4; i++) {
    emojiMaps['weibo-' + i] = emoji('weibo', i, 'png');
  }

  function pjax_valine() {
    if(!document.querySelectorAll("#valine_container")[0])return;

    let pagePlaceholder = $.trim($('#pjax-comment-placeholder').text()) || "快来评论吧~";

    let path = $.trim($('#pjax-comment-path').text());
    if (path.length == 0) {
      let defaultPath = '';
      path = defaultPath || decodeURI(window.location.pathname);
    }

    var valine = new Valine();
    valine.init({
      el: '#valine_container',
      meta: meta,
      placeholder: pagePlaceholder,
      path: path,
      appId: "",
      appKey: "",
      pageSize: '10',
      avatar: 'robohash',
      lang: 'zh-cn',
      visitor: 'true',
      highlight: 'true',
      mathJax: 'false',
      enableQQ: 'true',
      recordIP: false,
      requiredFields: requiredFields,
      emojiCDN: 'https://cdn.jsdelivr.net/gh/volantis-x/cdn-emoji/valine/',
      emojiMaps: emojiMaps
    })
  }

  $(function () {
    pjax_valine();
  });
</script>




  
<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5/lib/darkmode-js.min.js" aysc></script>

<script type="text/javascript">
function getClientHeight(){
  var clientHeight=0;
  if(document.body.clientHeight&&document.documentElement.clientHeight){
  var clientHeight = (document.body.clientHeight<document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
  }else{
  var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;
  }
  return clientHeight;
}
function supportCss3(style) {
  var prefix = ['webkit', 'Moz', 'ms', 'o'],
  i,
  humpString = [],
  htmlStyle = document.documentElement.style,
  _toHumb = function (string) {
  return string.replace(/-(\w)/g, function ($0, $1) {
  return $1.toUpperCase();
  });
  };
  for (i in prefix)
  humpString.push(_toHumb(prefix[i] + '-' + style));
  humpString.push(_toHumb(style));
  for (i in humpString)
  if (humpString[i] in htmlStyle) return true;
  return false;
};
//配置信息
var options = {
  bottom: '60px',
  right: 'unset',
  left: '1400px',
  time: '0s',
  mixColor: '#f4f4f4',
  backgroundColor: '#f4f4f4',
  buttonColorDark: '#333',
  buttonColorLight: '#ddd',
  saveInCookies: true,
  label: '',
  autoMatchOsTheme: true
};
// 卡片兼容处理 mix-blend-mode 与 effect: [blur] 冲突

function pjax_darkmodejs(){
  
  if(!supportCss3('mix-blend-mode'))return;
  var checkExist2 = setInterval(function() {
     if (typeof jQuery == 'undefined'){return;}
     clearInterval(checkExist2);
     var TopFlag=getClientHeight();
    $(window).scroll(function(){
      var top = $(document).scrollTop();
      if(top > TopFlag) {
        $(".darkmode-layer").css("mix-blend-mode","normal");
        $(".darkmode-layer").css("background-color","#222");
      }else{
        $(".darkmode-layer").css("mix-blend-mode","difference");
        $(".darkmode-layer").css("background-color","");
      }
    })
  }, 100);
  
}
// mix-blend-mode support?
if(supportCss3('mix-blend-mode')){
  window.darkmode = new Darkmode(options);
  
  window.darkmode.showWidget();
  
  pjax_darkmodejs();
}
////////////////Development///////////////////////
//////////////darkmode模式切换////////////////////
//window.darkmode.toggle();                     //
//////////////darkmode模式判断////////////////////
//console.log(window.darkmode.isActivated())    //
//////////////////////////////////////////////////
</script>





  
<script src="/blog/js/app.js"></script>




  
    
<script src="/blog/js/search.js"></script>

  


<!-- optional -->

  <script>
const SearchServiceimagePath="https://cdn.jsdelivr.net/gh/volantis-x/cdn-volantis@master/img/";
const ROOT =  ("/blog/" || "/").endsWith('/') ? ("/blog/" || "/") : ("/blog//" || "/" );
(function ($) {
  
    customSearch = new HexoSearch({
      imagePath: SearchServiceimagePath
    });
  
})(jQuery);

</script>





  
<script src="https://cdn.jsdelivr.net/npm/node-waves@0.7.6/dist/waves.min.js"></script>

  <script type="text/javascript">
    $(function () {
      Waves.attach('.flat-btn', ['waves-button']);
      Waves.attach('.float-btn', ['waves-button', 'waves-float']);
      Waves.attach('.float-btn-light', ['waves-button', 'waves-float', 'waves-light']);
      Waves.attach('.flat-box', ['waves-block']);
      Waves.attach('.float-box', ['waves-block', 'waves-float']);
      Waves.attach('.waves-image');
      Waves.init();
    });
  </script>



  
<script src="https://cdn.jsdelivr.net/gh/volantis-x/cdn-volantis@2/js/comment_typing.js"></script>




  
    
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.18.1/build/highlight.min.js"></script>

    <script>hljs.initHighlightingOnLoad();</script>
  



  <script defer>

  const LCCounter = {
    app_id: 'u9j57bwJod4EDmXWdxrwuqQT-MdYXbMMI',
    app_key: 'jfHtEKVE24j0IVCGHbvuFClp',
    custom_api_server: '',

    // 查询存储的记录
    getRecord(Counter, url, title) {
      return new Promise(function (resolve, reject) {
        Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({url})))
          .then(resp => resp.json())
          .then(({results, code, error}) => {
            if (code === 401) {
              throw error;
            }
            if (results && results.length > 0) {
              var record = results[0];
              resolve(record);
            } else {
              Counter('post', '/classes/Counter', {url, title: title, times: 0})
                .then(resp => resp.json())
                .then((record, error) => {
                  if (error) {
                    throw error;
                  }
                  resolve(record);
                }).catch(error => {
                console.error('Failed to create', error);
                reject(error);
              });
            }
          }).catch((error) => {
          console.error('LeanCloud Counter Error:', error);
          reject(error);
        });
      })
    },

    // 发起自增请求
    increment(Counter, incrArr) {
      return new Promise(function (resolve, reject) {
        Counter('post', '/batch', {
          "requests": incrArr
        }).then((res) => {
          res = res.json();
          if (res.error) {
            throw res.error;
          }
          resolve(res);
        }).catch((error) => {
          console.error('Failed to save visitor count', error);
          reject(error);
        });
      });
    },

    // 构建自增请求体
    buildIncrement(objectId) {
      return {
        "method": "PUT",
        "path": `/1.1/classes/Counter/${ objectId }`,
        "body": {
          "times": {
            '__op': 'Increment',
            'amount': 1
          }
        }
      }
    },

    // 校验是否为有效的 UV
    validUV() {
      var key = 'LeanCloudUVTimestamp';
      var flag = localStorage.getItem(key);
      if (flag) {
        // 距离标记小于 24 小时则不计为 UV
        if (new Date().getTime() - parseInt(flag) <= 86400000) {
          return false;
        }
      }
      localStorage.setItem(key, new Date().getTime().toString());
      return true;
    },

    addCount(Counter) {
      var enableIncr = '' === 'true' && window.location.hostname !== 'localhost';
      enableIncr = true;
      var getterArr = [];
      var incrArr = [];
      // 请求 PV 并自增
      var pvCtn = document.querySelector('#lc-sv');
      if (pvCtn || enableIncr) {
        var pvGetter = this.getRecord(Counter, 'https://hardydragon.gitee.io/blog' + '/#lc-sv', 'Visits').then((record) => {
          incrArr.push(this.buildIncrement(record.objectId))
          var eles = document.querySelectorAll('#lc-sv #number');
          if (eles.length > 0) {
            eles.forEach((el,index,array)=>{
              el.innerText = record.times + 1;
              if (pvCtn) {
                pvCtn.style.display = 'inline';
              }
            })
          }
        });
        getterArr.push(pvGetter);
      }

      // 请求 UV 并自增
      var uvCtn = document.querySelector('#lc-uv');
      if (uvCtn || enableIncr) {
        var uvGetter = this.getRecord(Counter, 'https://hardydragon.gitee.io/blog' + '/#lc-uv', 'Visitors').then((record) => {
          var vuv = this.validUV();
          vuv && incrArr.push(this.buildIncrement(record.objectId))
          var eles = document.querySelectorAll('#lc-uv #number');
          if (eles.length > 0) {
            eles.forEach((el,index,array)=>{
              el.innerText = record.times + (vuv ? 1 : 0);
              if (uvCtn) {
                uvCtn.style.display = 'inline';
              }
            })
          }
        });
        getterArr.push(uvGetter);
      }

      // 请求文章的浏览数，如果是当前页面就自增
      var allPV = document.querySelectorAll('#lc-pv');
      if (allPV.length > 0 || enableIncr) {
        for (i = 0; i < allPV.length; i++) {
          let pv = allPV[i];
          let title = pv.getAttribute('data-title');
          var url = 'https://hardydragon.gitee.io/blog' + pv.getAttribute('data-path');
          if (url) {
            var viewGetter = this.getRecord(Counter, url, title).then((record) => {
              // 是当前页面就自增
              let curPath = window.location.pathname;
              if (curPath.includes('index.html')) {
                curPath = curPath.substring(0, curPath.lastIndexOf('index.html'));
              }
              if (pv.getAttribute('data-path') == curPath) {
                incrArr.push(this.buildIncrement(record.objectId));
              }
              if (pv) {
                var ele = pv.querySelector('#lc-pv #number');
                if (ele) {
                  if (pv.getAttribute('data-path') == curPath) {
                    ele.innerText = (record.times || 0) + 1;
                  } else {
                    ele.innerText = record.times || 0;
                  }
                  pv.style.display = 'inline';
                }
              }
            });
            getterArr.push(viewGetter);
          }
        }
      }

      // 如果启动计数自增，批量发起自增请求
      if (enableIncr) {
        Promise.all(getterArr).then(() => {
          incrArr.length > 0 && this.increment(Counter, incrArr);
        })
      }

    },


    fetchData(api_server) {
      var Counter = (method, url, data) => {
        return fetch(`${ api_server }/1.1${ url }`, {
          method,
          headers: {
            'X-LC-Id': this.app_id,
            'X-LC-Key': this.app_key,
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(data)
        });
      };
      this.addCount(Counter);
    },

    refreshCounter() {
      var api_server = this.app_id.slice(-9) !== '-MdYXbMMI' ? this.custom_api_server : `https://${ this.app_id.slice(0, 8).toLowerCase() }.api.lncldglobal.com`;
      if (api_server) {
        this.fetchData(api_server);
      } else {
        fetch('https://app-router.leancloud.cn/2/route?appId=' + this.app_id)
          .then(resp => resp.json())
          .then(({api_server}) => {
            this.fetchData('https://' + api_server);
          });
      }
    }

  };

  LCCounter.refreshCounter();

  document.addEventListener('pjax:complete', function () {
    LCCounter.refreshCounter();
  });
</script>



<!-- more -->

  
  <script></script>




    
      


<script src="https://cdn.jsdelivr.net/npm/pjax@0.2.8/pjax.min.js"></script>

<!-- 样式位于：source/css/_third-party/pjaxanimate.styl -->

<div class="pjax-animate">
  
    <script src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js"></script>
    <div id="loading-bar-wrapper"><script>NProgress.configure({parent:"#loading-bar-wrapper",trickleSpeed: 100})</script></div>
    <script>
      window.ShowLoading = function() {
        NProgress.start();
      };
      window.HideLoading = function() {
        NProgress.done();
      }
    </script>
  
</div>

<script>
    var pjax;
    document.addEventListener('DOMContentLoaded', function () {
      pjax = new Pjax({
        elements: 'a[href]:not([href^="#"]):not([href="javascript:void(0)"]):not([pjax-fancybox])',
        selectors: [
          "title",
          "#pjax-container",
          "#pjax-header-nav-list"
        ],
        cacheBust: false,   // url 地址追加时间戳，用以避免浏览器缓存
        timeout: 5000
      });
    });

    document.addEventListener('pjax:send', function (e) {
      window.stop(); // 相当于点击了浏览器的停止按钮

      try {
        var currentUrl = window.location.pathname;
        var targetUrl = e.triggerElement.href;
        var banUrl = [""];
        if (banUrl[0] != "") {
          banUrl.forEach(item => {
            if(currentUrl.indexOf(item) != -1 || targetUrl.indexOf(item) != -1) {
              window.location.href = targetUrl;
            }
          });
        }
      } catch (error) {}

      window.subData = null; // 移除标题（用于一二级导航栏切换处）
      if (typeof $.fancybox != "undefined") {
        $.fancybox.close();    // 关闭弹窗
      }
      $('.l_header .switcher .s-search').removeClass('active'); // 关闭移动端激活的搜索框
      $('.l_header').removeClass('z_search-open'); // 关闭移动端激活的搜索框
      $('.wrapper').removeClass('sub'); // 跳转页面时关闭二级导航

      // 解绑事件 避免重复监听
      $('.s-top').unbind('click');
      $('.menu a').unbind('click');
      $(window).unbind('resize');
      $(window).unbind('scroll');
      $(document).unbind('scroll');
      $(document).unbind('click');
      $('body').unbind('click');
      window.ShowLoading();
    });

    document.addEventListener('pjax:complete', function () {
      // 关于百度统计对 SPA 页面的处理：
      // 方案一：百度统计>管理>单页应用设置中，打开开启按钮即可对SPA进行统计。 https://tongji.baidu.com/web/help/article?id=324
      // 方案二：取消注释下列代码。 https://tongji.baidu.com/web/help/article?id=235
      // 

      // 关于谷歌统计对 SPA 页面的处理：
      // 当应用以动态方式加载内容并更新地址栏中的网址时，也应该更新通过 gtag.js 存储的网页网址。
      // https://developers.google.cn/analytics/devguides/collection/gtagjs/single-page-applications?hl=zh-cn
      

      $('.nav-main').find('.list-v').not('.menu-phone').removeAttr("style",""); // 移除小尾巴的移除
      $('.menu-phone.list-v').removeAttr("style",""); // 移除小尾巴的移除
      $('script[data-pjax], .pjax-reload script').each(function () {
        $(this).parent().append($(this).remove());
      });
      try{
          if (typeof $.fancybox == "undefined") {
            SCload_fancybox();
          } else {
            pjax_fancybox();
          }
        
          
          if ('.cover-backstretch') {
            $('.cover-backstretch').backstretch("resize");
            if($('.cover-wrapper').is(':hidden')){
              $('.cover-backstretch').backstretch("pause");
            }else{
              $('.cover-backstretch').backstretch("next");
            }
          } else {
            $.backstretch("resize");
            if($('.cover-wrapper').is(':hidden')){
              $.backstretch("pause");
            }else{
              $.backstretch("next");
            }
          }
        
        
        document.querySelectorAll('pre code').forEach((block) => {
          hljs.highlightBlock(block);
        });
        
        
          pjax_scrollrebeal();
        
        
        
          pjax_initCopyCode();
        
        
          pjax_valine();
        
        
        
        
        
          pjax_darkmodejs();
        
      } catch (e) {
        console.log(e);
      }
      window.HideLoading();
    });

    document.addEventListener('pjax:error', function (e) {
      window.HideLoading();
      window.location.href = e.triggerElement.href;
    });
</script>

    
  </div>
</body>
</html>
